import request from './request'

/**
 * 获取图形验证码
 */
export const getCaptcha = () => {
  return request({
    url: '/auth/captcha',
    method: 'get'
  })
}

/**
 * 发送邮箱验证码
 * @param {string} email - 邮箱地址
 * @param {string} type - 类型：login(登录) 或 register(注册)
 */
export const sendEmailCode = (email, type) => {
  return request({
    url: '/auth/send-code',
    method: 'post',
    params: { email, type }
  })
}

/**
 * 检查邮箱是否存在
 */
export const checkEmail = (email) => {
  return request({
    url: '/auth/check-email',
    method: 'get',
    params: { email }
  })
}

/**
 * 邮箱注册
 */
export const registerByEmail = (data) => {
  return request({
    url: '/auth/register/email',
    method: 'post',
    data
  })
}

/**
 * 邮箱验证码登录
 */
export const loginByEmail = (data) => {
  return request({
    url: '/auth/login/email',
    method: 'post',
    data
  })
}

/**
 * 更新邮箱
 */
export const updateEmail = (data) => {
  return request({
    url: '/auth/update-email',
    method: 'put',
    data
  })
}

/**
 * 刷新Token
 */
export const refreshToken = (refreshToken) => {
  return request({
    url: '/auth/refresh',
    method: 'post',
    data: { refreshToken }
  })
}

/**
 * 退出登录
 */
export const logout = () => {
  return request({
    url: '/auth/logout',
    method: 'post'
  })
}
